<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--导入easyui样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>订单管理</title>
</head>
<script type="text/javascript">
$(function () {
	  $('#dg').datagrid({  
		url:'allorder_json.action',
		columns:[[ 
	           {field:'ck',checkbox:true},
	    	   {field:'oid',title:'订单编号',width:80,editor:'text'},    
	    	   {field:'sendname',title:'寄件人',width:80,editor:'text'},
	    	   {field:'sendtel',title:'寄件人电话',width:133,editor:'numberbox'},
	    	   {field:'addressname',title:'收件人',width:80,editor:'text'},    
	    	   {field:'addresstel',title:'收件人电话',width:133,editor:'numberbox'},
	    	   {field:'place',title:'发件地',width:80,editor:'text'},
	    	   {field:'fhdate',title:'发货日期',width:120,editor:'datetimebox'},    
	    	   {field:'receipt',title:'收件地',width:80,editor:'text'},
	    	   {field:'paystate',title:'支付状态',width:80,	    		   
      		 		editor:{
           					type:'combobox' ,
          	 			options:{
              				data:[{id:'未支付' , val:'未支付'},{id:'已支付' , val:'已支付'}] ,
               				valueField:'id' , 
               				textField:'val' ,
               				required:true , 
               				panelHeight:'auto',
              				missingMessage:'必填!'
           				}
       				}
		    	},
	    	   {field:'orderstatus',title:'订单状态',width:80,
		    		   editor:{
		           			type:'combobox' ,
		           			options:{
		    		   			url:'oderstu_json.action',    
		    		    		valueField:'text',    
		    		    		textField:'text', 
		    		    		panelHeight:'auto',
		           			}
			    	   }
			    	},    
	    	   {field:'type',title:'订单类别',width:80,
	    		   editor:{
	           			type:'combobox' ,
	           			options:{
	    		   			url:'odertype_json.action',    
	    		    		valueField:'text',    
	    		    		textField:'text', 
	    		    		panelHeight:'auto',
	           			}
		    	   }
	    	   },
	    	   {field:'goodsname',title:'物品名',width:80,editor:'text'},
	    	   {field:'goodstype',title:'物品类别',width:80,
	    		   editor:{
	           			type:'combobox' ,
	           			options:{
	    		   			url:'goodstype_json.action',    
	    		    		valueField:'text',    
	    		    		textField:'text', 
	    		    		panelHeight:'auto',
	           			}
		    	   }
	    	   },    
	    	   {field:'weight',title:'物品重量',width:80,editor:'text'},
	    	   {field:'volume',title:'物品体积',width:80,editor:'text'},
	    	   {field:'bedisprice',title:'投递费用',width:80,editor:'text'},
	    	   {field:'traprice',title:'运输费用',width:80,editor:'text'},
	    	   {field:'tariff',title:'总费用',width:80,editor:'text'},
	    	   {field:'plate',title:'车辆',width:80,editor:'text'},
	    	   {field:'remarks',title:'备注',width:80,editor:'text'},	    	       
	    	   ]] ,
	    	      fitColumns:true,
	    	      pagination:true,
	    	      pagePosition:'bottom',
	    	      pageSize:10,
	    	      pageList:[5,10,20],
	    	      onClickCell: onClickCell,
	    	      toolbar: [{
// ----------------------------订单支付状态------------------------------------
	    iconCls:'icon-edit',
	    text:'确认已支付',
	    handler: function(){
	    	var  orders = $('#dg').datagrid('getSelections');
			if(orders.length==1){
	    	$("#uptorder").dialog("open").dialog('setTitle', '确认已支付');
	    	$("#oid1").val(orders[0].oid);
	    	$("#ddid").text(orders[0].oid);
	    	$("#cc1").combobox('setValue',orders[0].paystate);	
	    	$('#sve').linkbutton({    
	    		onClick:function(){
	    			if("已支付"==$("#cc1").combobox('getValue')){	    			
	    				    	$("#uporder").submit();			    	
	    			}else{
	    				$.messager.alert('error','不能提交未支付的订单','info');
	    			}
	    		}
	    	})
			}else{
				$.messager.confirm('信息','请选择一张需要修改的订单',function(r){    
				    if (r){    
				    	$('#dg').datagrid('uncheckAll');    
				    }    
				}); } 
	    	
	    } },'_',{
	    	iconCls:'icon-edit',
		    text:'修改订单状态',
		    handler: function(){
		    	var  orders = $('#dg').datagrid('getSelections');
				if(orders.length==1){
					$("#uptorder3").dialog("open").dialog('setTitle', '修改订单状态');
			    	$("#oid3").val(orders[0].oid);
			    	$("#ddid3").text(orders[0].oid);
			    	$("#statu1").combobox('setValue',orders[0].orderstatus);
			    	
			    	$('#sve3').linkbutton({    
			    		onClick:function(){
			     
		    		if("已退订"==$("#statu1").combobox('getValue')){
    				$.messager.confirm('信息',"确认订单 "+orders[0].oid+"需要退订",function(r){    
    				    if (r){    
    				    	$("#remorder").dialog("open").dialog('setTitle', '取消订单'); 
    						$('#fhorder').text("确认取消订单  "+ orders[0].oid);
    						var order = JSON.stringify(orders[0]);
    						$("#qxorder").val(order);
    						$('#dle1').linkbutton({    
    				    		onClick:function(){
    				    			$("#tding").submit();		
    				    		}
    				    	})
    				   		 }
    					});	
    				}else{
    					$("#uporder3").submit();
    					} 			    		
			    		}
			    		}) 
				}else{
					$.messager.confirm('信息','请选择一张需要修改的订单',function(r){    
					    if (r){    
					    	$('#dg').datagrid('uncheckAll');    
					    }    
					}); } 
		    }	    	
	    }],	      
	})   
	//配送点下拉列表
	$('#fhd').combobox({    
	    url:'point_json.action',    
	    valueField:'text',    
	    textField:'text' ,
	    panelHeight:'auto',
	});
	//代理点下拉列表
	$('#sjd').combobox({    
	    url:'proxy_json.action',    
	    valueField:'text',    
	    textField:'text' ,
	    panelHeight:'auto',
	});
	//订单类别下拉列表
	$('#otype').combobox({    
	    url:'odertype_json.action',    
	    valueField:'text',    
	    textField:'text', 
	    panelHeight:'auto',
	});	
	//订单状态下拉列表
	$('#statu').combobox({    
	    url:'oderstu_json.action',    
	    valueField:'text',    
	    textField:'text', 
	    panelHeight:'auto',
	});		
	//订单状态下拉列表
	$('#statu1').combobox({    
	    url:'oderstu_json.action',    
	    valueField:'text',    
	    textField:'text', 
	    panelHeight:'auto',
	    editable : false,
	});	
	//时间段设置
	$("#str").datebox({
        onSelect : function(beginDate){
         $('#over').datebox().datebox('calendar').calendar({
          validator: function(date){
             var d1 = new Date(beginDate.getFullYear(), beginDate.getMonth(), beginDate.getDate());
           		return d1<=date;        
          }
         });
        }
   });
	//提交退订订单
	$('#tding').form({
		url : 'tdingorder.action',
		success:function(xx){
				if(xx==null){
					$.messager.alert('error','取消失败！','info');							
				}else{
					$.messager.alert('信息',"取消成功,退订返回订单编号为 "+xx+"  ，请留意查看",'info');	
					$("#remorder").dialog("close");	
					$("#uptorder3").dialog("close");
	 				$('#dg').datagrid('reload');
				}
		}})	
	
	//配置修改订单状态按钮
		$('#uporder3').form({
		url : 'cxorder.action',
		success:function(xx){
			if(xx=="1"){
				$.messager.alert('信息','修改成功','info');	
				$("#uptorder3").dialog("close");		
 				$('#dg').datagrid('reload');			
			}else{
				$.messager.alert('error','修改失败！','info');
			}
	}})
	
	//配置修改支付状态按钮
	$('#uporder').form({
		url : 'uptorder.action',
		success:function(xx){
			if(xx=="1"){
				$.messager.alert('信息','修改成功','info');	
				$("#uptorder").dialog("close");		
 				$('#dg').datagrid('reload');			
			}else{
				$.messager.alert('error','修改失败！','info');
			}
	}})
	
//配置查找按钮
	$('#btn').linkbutton({    
		onClick:function(){
			$('#find').submit(); 
		}   
	});
	//条件查找返回数据	
	$(document).ready(function() {
			fLoadData();
			fLoadAllorders();
		})
		function fLoadData() {
			$('#find').form({
				url : 'findorders_json.action',
				success : function(data) {
					var vData = $.parseJSON(data);
					$('#dg').datagrid('loadData', vData); //将数据绑定到datagrid   
				}
			});
		}
	
 function fLoadAllorders(){
	 $('#btn1').linkbutton({    
			onClick:function(){
				$.ajax({
			    url:'allorder_json.action', 
			    type:'post',
			    success:function(data){ 
						var vData = $.parseJSON(data); 
						$('#dg').datagrid('loadData', vData); //将数据绑定到datagrid   
					}
				})
				}
			}); 
		}

})
</script>
<body>
<!---------------------------- 查找 ----------------------------->
<form id="find" method="post"> 
<div>
查找方式：<br>
寄件地<input id="fhd" name="order1.place" ><span>收件地<input id="sjd" name="order1.receipt" ></span>
寄件人姓名<input id="sendname" name="order1.sendname" type="text" class="easyui-validatebox"/><br>
订单状态<input id="statu" name="order1.orderstatus" ><span>订单类别<input id="otype" name="order1.type"/></span>
支付状态<select id="cc" class="easyui-combobox" name="order1.paystate"  data-options="panelHeight:'auto',editable:false">   
    <option></option>
    <option>未支付</option>   
    <option>已支付</option>   
</select>
</div>
发货日期：开始日期<input id="str" name="strfhdate" type="text" class="easyui-datebox"  data-options="panelHeight:'auto'">
<span>结束日期<input id="over" name="overfhdate" type="text" class="easyui-datebox" data-options="panelHeight:'auto'"></span> 
<a id="btn" style="width: 100px;" class="easyui-linkbutton">查找订单</a>
<a id="btn1" style="width: 100px;" class="easyui-linkbutton">查看所有订单</a>
</form>
<div>
<table id="dg"></table>
<div> 
<!------------------------------------- 订单支付修改 ----------------------------------------->
<div id="uptorder" class="easyui-dialog"  closed="true" buttons="#dlg1-buttons "  > 
<form id="uporder" method="post">
		<div  style="width: 200px;height: 100px;margin-top: 30px;margin-left: 30px">
		<input id="oid1" name="order2.oid"  style="display:none;"/>
	<p >修改订单 &nbsp;<span id="ddid"></span> &nbsp; 的支付状态</p> 
	支付状态：<select id="cc1" class="easyui-combobox" name="order2.paystate"  data-options="panelHeight:'auto',panelWidth:'auto',editable:false">   
   		 		<option></option>
    			<option>未支付</option>   
    			<option>已支付</option>   
				</select>	
		</div>	
       <div id="dlg1-buttons">
        <button id="sve"  class="easyui-linkbutton"  iconcls="icon-ok">确认修改</button>
        <a id="cancl" class="easyui-linkbutton" onclick="javascript:$('#uptorder').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</form>
</div>

<!------------------------------------- 订单状态修改 ----------------------------------------->
<div id="uptorder3" class="easyui-dialog"  closed="true" buttons="#dlg3-buttons "  > 
<form id="uporder3" method="post">
		<div  style="width: 200px;height: 100px;margin-top: 30px;margin-left: 30px">
		<input id="oid3" name="oid"  style="display:none;"/>
	<p >修改订单 &nbsp;<span id="ddid3"></span> &nbsp; 的状态</p> 
	订单状态<input id="statu1" name="ostatus" style="width: 100px;">
		</div>		
       <div id="dlg3-buttons">
        <button id="sve3"  class="easyui-linkbutton"  iconcls="icon-ok">确认修改</button>
        <a id="cancl3" class="easyui-linkbutton" onclick="javascript:$('#uptorder3').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</form>
</div>

<!------------------------------------- 退订订单 ----------------------------------------->
<div id="remorder" class="easyui-dialog"  closed="true" buttons="#dlg2-buttons" > 
<form id="tding" method="post">
<div  style="width: 200px;height: 100px;margin-top: 30px;margin-left: 30px">
		选择退订，将产生一张新的订单来返回原物件,并产生新的配送费用<br>
			<span id="fhorder" style="font-size: medium;font-style: oblique;"></span>
		<input id="qxorder" name="qxorder" style="display:none;">
</div>
       <div id="del2-buttons">
        <button id="del1"  class="easyui-linkbutton"  iconcls="icon-save">确认取消</button>
        <a id="cancl1" class="easyui-linkbutton" onclick="javascript:$('#remorder').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</form>
</div>
 
</body>

<script type="text/javascript">

$.extend($.fn.datagrid.methods, {
	editCell: function(jq,param){
		return jq.each(function(){
			var opts = $(this).datagrid('options');
			var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
			for(var i=0; i<fields.length; i++){
				var col = $(this).datagrid('getColumnOption', fields[i]);
				col.editor1 = col.editor;
				if (fields[i] != param.field){
					col.editor = null;
				}
			}
			$(this).datagrid('beginEdit', param.index);
			for(var i=0; i<fields.length; i++){
				var col = $(this).datagrid('getColumnOption', fields[i]);
				col.editor = col.editor1;
			}
		});
	}
});

var editIndex = undefined;
function endEditing(){
	if (editIndex == undefined){return true}
	if ($('#dg').datagrid('validateRow', editIndex)){
		$('#dg').datagrid('endEdit', editIndex);
		editIndex = undefined;
		return true;
	} else {
		return false;
	}
}
function onClickCell(index, field){
	if (endEditing()){
		$('#dg').datagrid('selectRow', index)
				.datagrid('editCell', {index:index,field:field});
		editIndex = index;
	}
}
</script>

</html>